const BaseRest = require('../rest.js');

/**
 * 会员中心-用户基础信息相关接口
 */
module.exports = class extends BaseRest {
  constructor(ctx) {
    super(ctx);
    this.modelInstance = this.model('user_member');
  }

  // 所有的请求否必须登陆
  async __before(action) {
    try {
      this.userInfo = await this.ctx.session('userInfo');
    } catch (err) {
      this.userInfo = {};
    }

    // GET请求都必须登陆
    if (think.isEmpty(this.userInfo)) {
      this.ctx.status = 401;
      return this.ctx.fail(-1, '请登录后操作');
    }
  }

  async getAction() {
    const data = {};
    const uid = this.id;

    const user = await this.model('user').where({ id: uid }).find();
    if (think.isEmpty(user)) {
      return this.fail(1001, '用户不存在');
    }

    // const type = this.get('type') || "default";

    // 查基本信息
    // 直接会员信息
    data['member'] = await this.modelInstance.where({ puid: uid }).select();
    // 订单信息

    // 账户信息

    return this.success(data);
  }
};
